<?php
/**
 * @package Buffet
 * @subpackage Extensions
 */

/**
 * SearchHighlight class
 * 
 * {@internal Missing Long Description }}
 * 
 * @access	public
 * @since	0.5.2
 */
class SearchHighlight extends BF_Extension {
	const ID			= 'SearchHighlight';
	const NAME			= 'Highlight Search Terms';
	const DESCRIPTION	= 'Highlights Search Terms with jQuery. Based on <a href="http://weblogtoolscollection.com/archives/2009/04/10/how-to-highlight-search-terms-with-jquery/">this tutorial</a>.';
	
	function load() {
		add_action( 'init', array($this, 'enqueue_script') );
		add_action( 'wp_head', array($this, 'add_head') );
		add_action( 'bf_jquery', array($this, 'add_jquery') );
	}
	
	function enqueue_script() {
		wp_enqueue_script( 'highlight', get_template_directory_uri() . '/includes/js/jquery.highlight.js', array('jquery') );
	}
	
	function add_head() {
		$query  = attribute_escape( get_search_query() );
		
		if(strlen($query) > 0) {
    		echo '<script type="text/javascript">var hls_query  = "' . $query . '";</script>';
  		}
	}
	
	function add_jquery() {
		echo 'j(".hfeed").highlight(hls_query, 1, "hls");';
	}
	
}

/* End of file HelloWorld.php */
/* Location: ./includes/extensions/HelloWorld.php */
